package com.ruoyi.web.controller.market.form;

import java.util.List;
import java.util.Map;

import com.ruoyi.db.model.param.FormInfoProfitParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.FormInfoProfit;
import com.ruoyi.form.service.IFormInfoProfitService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.FormInfoProfitWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * profitController
 * 
 * @author ruoyi
 * @date 2022-11-23
 */
@Controller
@RequestMapping("/form/profit")
public class FormInfoProfitController extends BaseController
{
    private String prefix = "form/profit";

    @Autowired
    private IFormInfoProfitService formInfoProfitService;

//    @RequiresPermissions("form:profit:view")
    @GetMapping("/{formId}")
    public String profit(@PathVariable("formId") Long formId, ModelMap mmap)
    {
        mmap.put("formId", formId);
        return prefix + "/profit";
    }

    @GetMapping("/all")
    public String profitAll(ModelMap mmap)
    {
        List<Map<String, Object>> typeMapList = formInfoProfitService.selectProfitTypeMapList();
        mmap.put("typeMapList", typeMapList);

        return prefix + "/profitAll";
    }

    /**
     * 查询profit列表
     */
//    @RequiresPermissions("form:profit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FormInfoProfitParam formInfoProfit)
    {
        startPage();
        List<Map<String, Object>> mapList = formInfoProfitService.selectFormInfoProfitListMap(formInfoProfit);

        // 查询总的
        Map<String, Object> totalMap = formInfoProfitService.selectFormInfoProfitTotalMap(formInfoProfit);
        mapList.add(0, totalMap);

        mapList = new FormInfoProfitWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出profit列表
     */
//    @RequiresPermissions("form:profit:export")
    @Log(title = "profit", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FormInfoProfit formInfoProfit)
    {
        List<FormInfoProfit> list = formInfoProfitService.selectFormInfoProfitList(formInfoProfit);
        ExcelUtil<FormInfoProfit> util = new ExcelUtil<FormInfoProfit>(FormInfoProfit.class);
        return util.exportExcel(list, "profit数据");
    }

    /**
     * 新增profit
     */
    @GetMapping("/add/{formId}")
    public String add(@PathVariable("formId") Long formId, ModelMap mmap)
    {
        mmap.put("formId", formId);
        return prefix + "/add";
    }

    /**
     * 新增保存profit
     */
//    @RequiresPermissions("form:profit:add")
    @Log(title = "profit", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FormInfoProfit formInfoProfit)
    {
        return toAjax(formInfoProfitService.insertFormInfoProfit(formInfoProfit));
    }

    /**
     * 修改profit
     */
//    @RequiresPermissions("form:profit:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FormInfoProfit formInfoProfit = formInfoProfitService.selectFormInfoProfitById(id);
        mmap.put("formInfoProfit", formInfoProfit);
        return prefix + "/edit";
    }

    /**
     * 修改保存profit
     */
//    @RequiresPermissions("form:profit:edit")
    @Log(title = "profit", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FormInfoProfit formInfoProfit)
    {
        return toAjax(formInfoProfitService.updateFormInfoProfit(formInfoProfit));
    }

    /**
     * 删除profit
     */
//    @RequiresPermissions("form:profit:remove")
    @Log(title = "profit", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(formInfoProfitService.deleteFormInfoProfitByIds(ids));
    }
}
